package com.kiven.thread;

import java.lang.Runnable;

public class ThreadDemo7 implements Runnable {
	private int state = 0;
	
	public void setState(int state) {
		this.state = state;
	}
	@Override
	public synchronized void run() {
		int index =0;
		for(int i=0; i<100; i++) {
			System.out.print(index++);
			
			if(i == 50) {
				System.out.println("*****i=50，线程进入等待(wait)状态*****"); 
				//等待状态
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			//恢复状态
			/*if() {
				this.notify();
			}*/
		}
	}
	
	public static void main(String[] args) throws Exception {
		ThreadDemo7 r = new ThreadDemo7();
		Thread t1 = new Thread(r);
		Thread t2 = new Thread(r);
		Thread t3 = new Thread(r);
		
		t1.start();
		System.out.println("线程t1进入睡眠——10");
		t1.sleep(15000);
		
		r.setState(1);
		t2.start();
		System.out.println("线程t2进入睡眠——10");
		t2.sleep(15000);
		
		r.setState(2);
		System.out.println("线程t3唤醒进入睡眠的线程...");
		t3.start();
	}

}
